package com.bestcem.xm.ticket.controller.convert;

import com.bestcem.xm.ticket.controller.vo.SimpleTicketConfigVO;
import com.bestcem.xm.ticket.entity.mongo.TicketConfig;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/18 11:13
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TicketConfigConvert {
    /**
     * TicketConfig 转 SimpleTicketConfigVO
     *
     * @param entity TicketConfig实体
     * @return 对应的 SimpleTicketConfigVO
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/18 11:23
     */
    public static SimpleTicketConfigVO entityToSimpleTicketConfigVO(TicketConfig entity) {
        if (Objects.isNull(entity)) {
            return null;
        }
        SimpleTicketConfigVO simpleTicketConfigVO = new SimpleTicketConfigVO();
        simpleTicketConfigVO.setId(entity.getId());
        simpleTicketConfigVO.setTitle(entity.getTitle());
        simpleTicketConfigVO.setState(entity.getState());
        simpleTicketConfigVO.setNeedDeal(entity.getNeedDeal());
        return simpleTicketConfigVO;
    }

    /**
     * TicketConfig列表 转 SimpleTicketConfigVO列表
     *
     * @param entityList TicketConfig实体列表
     * @return 对应的 SimpleTicketConfigVO列表
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/18 11:23
     */
    public static List<SimpleTicketConfigVO> entityToSimpleTicketConfigVOList(List<TicketConfig> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return new ArrayList<>();
        }
        List<SimpleTicketConfigVO> simpleTicketConfigVOList = new ArrayList<>();
        for (TicketConfig ticketConfig : entityList) {
            SimpleTicketConfigVO ticketConfigVO = entityToSimpleTicketConfigVO(ticketConfig);
            if (Objects.nonNull(ticketConfig)) {
                simpleTicketConfigVOList.add(ticketConfigVO);
            }
        }
        return simpleTicketConfigVOList;
    }
}
